package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class LoginDemo {
    public static void main(String[] args) {
        UserInfo inputObject = InputUtil.getInputObject(new UserInfo(), "欢迎登陆", "登录");
        System.out.println(inputObject);
        try(Connection connection = DBUtil.getConnection())
        {
            Statement statement = connection.createStatement();
            String sql="select username,password,nickname,age " +
                    "from userinfo " +
                    "where username='"+inputObject.getUsername()+"'and password='"+inputObject.getPassword()+"'";
            ResultSet rs = statement.executeQuery(sql);
            if(rs.next()){
                System.out.println("登陆成功");
                System.out.println("欢迎"+rs.getString("nickname")+"("+rs.getInt("age")+"岁)");
            }else{
                System.out.println("登陆失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
